package com.oms.servlet;

import com.liudecai.utils.servlet.BaseServlet;
import com.oms.bean.Admin;
import com.oms.dao.AdminDao;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class AdminServlet
 */
@WebServlet("/AdminServlet")
public class AdminServlet extends BaseServlet {
	public static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public AdminServlet() {
        
    }

    public String logincheck(HttpServletRequest request, HttpServletResponse response) throws SQLException {
		String admin = request.getParameter("admin");
		String password = request.getParameter("password");
		HttpSession session = request.getSession();
		session.setAttribute("u_admin", admin);
		AdminDao dao = new AdminDao();
		Admin logincheck = dao.LoginCheck(admin, password);
		if (logincheck != null) {
			System.out.println("登陆成功");
			return "r:/admin/show_class.jsp";
		} else {
			System.out.println("登陆失败");
			return "r:/admin/error.jsp";
		}
	}

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
